package com.youlai.system.controller;

import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.result.Result;
import com.youlai.system.service.AirPlaneService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.system.model.form.AirPlaneForm;
import com.youlai.system.model.query.AirPlaneQuery;
import com.youlai.system.model.vo.AirPlaneVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 机型管理前端控制层
 *
 * @author youlai买国涛
 * @since 2024-11-05 16:30
 */
@Tag(name = "机型管理接口")
@RestController
@RequestMapping("/api/v1/airPlanes")
@RequiredArgsConstructor
public class AirPlaneController  {

    private final AirPlaneService airPlaneService;

    @Operation(summary = "机型管理分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:airPlane:query')")
    public PageResult<AirPlaneVO> getAirPlanePage(AirPlaneQuery queryParams ) {
        IPage<AirPlaneVO> result = airPlaneService.getAirPlanePage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增机型管理")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:airPlane:add')")
    public Result<Void> saveAirPlane(@RequestBody @Valid AirPlaneForm formData ) {
        boolean result = airPlaneService.saveAirPlane(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取机型管理表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:airPlane:edit')")
    public Result<AirPlaneForm> getAirPlaneForm(
            @Parameter(description = "机型管理ID") @PathVariable Long id
    ) {
        AirPlaneForm formData = airPlaneService.getAirPlaneFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改机型管理")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:airPlane:edit')")
    public Result<Void> updateAirPlane(
            @Parameter(description = "机型管理ID") @PathVariable Long id,
            @RequestBody @Validated AirPlaneForm formData
    ) {
        boolean result = airPlaneService.updateAirPlane(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除机型管理")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:airPlane:delete')")
    public Result<Void> deleteAirPlanes(
            @Parameter(description = "机型管理ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = airPlaneService.deleteAirPlanes(ids);
        return Result.judge(result);
    }
}
